<template>
  <el-header>
    <div class="header-left flex align-items-center">
      <svg class="icon icon-logo" aria-hidden="true">
        <use xlink:href="#icon-zhuti"></use>
      </svg>
      <span>春田花花</span>
    </div>
    <div class="header-right">
      <el-dropdown @command="handleCommand">
        <div class="el-dropdown-link flex align-items-center">
          用户名：{{ username }}<i class="el-icon-arrow-down el-icon--right"></i>
        </div>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item>用户信息</el-dropdown-item>
          <el-dropdown-item divided command="logout">退出</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </el-header>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
  computed: {
    ...mapGetters({
      username: 'username'
    })
  },
  methods: {
    handleCommand (command) {
      if (command === 'logout') {
        this.logout()
      }
    },
    async logout () {
      await this.$http.post('/logout')
      await this.$store.dispatch('logout')
      this.$router.push({
        name: 'Login'
      })
    }
  }
}
</script>
<style lang="scss" scoped>
  @import "../assets/scss/var.scss";
  $headerHeight: 60px;
  header {
    width: 100%;
    height: $headerHeight;
    background-color: darken($blue, 20);
    color: $white;
  }
  .header-left {
    float: left;
    margin-top: 10px;
    font-size: 20px;
    .icon-logo {
      $width: 36px;
      width: $width;
      height: $width;
    }
  }
  .header-right {
    float: right;
    .el-dropdown-link {
      height: $headerHeight;
      color: $white;
      font-size: 16px;
    }
  }
</style>

